package com.sy;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

/**
 * @className: ResultVo
 * @author: Mr.Liu
 * @date: 2025/10/27 14:55
 * @Version: 1.0
 * @description:统一的响应结果
 */
@Data
@Schema(description = "统一响应封装类")
public class ResultVO<T> {
    @Schema(description = "响应码",example = "200")
    private Integer code;
    @Schema(description = "响应信息")
    private String msg; //错误信息
    @Schema(description = "响应数据")
    private T data; //数据

    public static <T> ResultVO<T> success() {
        ResultVO<T> result = new ResultVO<T>();
        result.code = 200;
        result.msg="success";
        return result;
    }

    public static <T> ResultVO<T> success(T object) {
        ResultVO<T> result = new ResultVO<T>();
        result.data = object;
        result.code = 200;
        result.msg="success";
        return result;
    }
    public static <T> ResultVO<T> success(T object,String msg) {
        ResultVO<T> result = new ResultVO<T>();
        result.data = object;
        result.code = 200;
        result.msg= msg;
        return result;
    }

    public static <T> ResultVO<T> error(String msg) {
        ResultVO result = new ResultVO();
        result.msg = msg;
        result.code = 500;
        return result;
    }
    public static <T> ResultVO<T> error() {
        ResultVO result = new ResultVO();
        result.msg = "error";
        result.code = 500;
        return result;
    }
}
